<?php
require_once ("../utils/ConnectionFactory.php");
require_once ("../persistance/data/ResponsableDO.php");

/**
 *
 * @author Quentin Laujac, Charles Hurtevent
 *
 */
class ResponsableDAO {

	/**
	 * Retourne un ResponsableDO, correspondant a un responsable
	 *
	 * @param String $login
	 * @return NULL ResponsableDO
	 */
	public function getResponsableDO($login) {
		$connection = ConnectionFactory::getConnection ();
		$reponse = $connection->query ( "SELECT * FROM responsable WHERE login LIKE '" . $login . "'" );
		if ($reponse == null || $reponse->rowCount () == 0) {
			return null;
		}

		$donnee = $reponse->fetch ();
		$responsableDO = $this->setResponsableDO ( $donnee );

		return $responsableDO;
	}

	/**
	 *
	 * retourne un ResponsableDO en fonction de son numResponsable
	 * @param unknown_type $numResponsable
	 */
	public function getResponsableDOByNumResponsable($numResponsable) {
		$connection = ConnectionFactory::getConnection ();
		$reponse = $connection->query ( "SELECT * FROM responsable WHERE num_resp = " . $numResponsable);
		if ($reponse == null || $reponse->rowCount () == 0) {
			return null;
		}

		$donnee = $reponse->fetch ();
		$responsableDO = $this->setResponsableDO ( $donnee );

		return $responsableDO;
	}

	private function setResponsableDO($donnee) {
		$responsableDO = new ResponsableDO ();
		$responsableDO->setNom ( $donnee ['nom'] );
		$responsableDO->setLogin ( $donnee ['login'] );
		$responsableDO->setPrenom ( $donnee ['prenom'] );
		$responsableDO->setPassword ( $donnee ['password'] );
		$responsableDO->setNumeroLieu ( $donnee ['num_lieu'] );
		$responsableDO->setNumeroStructure ( $donnee ['num_struct'] );
		$responsableDO->setNumeroResponsable ( $donnee ['num_resp'] );

		return $responsableDO;
	}
}
